/*
 * GPIO2_Key6.h
 *
 *  Created on: Mar 22, 2021
 *      Author: xrj
 */

#ifndef INC_GPIO2_KEY6_H_
#define INC_GPIO2_KEY6_H_

#include "GPIO5.h"

/*
 *     __VDD__              __VDD__
 *        |                    |
 *       | |R1              R3| |
 *       |_|                  |_|
 *        |.           D1      |.
 *      K1  \  __./ __|\|__      \ K5
 *        |   |  K3   |/|  |   |
 *PinA ===0---|            |---0=== PinB
 *        |.  |__./ __|/|__|   |.
 *      K2  \    K4   |\|        \ K6
 *        |            D2      |
 *       | |                  | |
 *       |_|R2              R4|_|
 *       _|_                  _|_
 *        -  GND               -  GND
 *
 *         Resistance are 20kOhm
 */

//Pin A
#define A_Port GPIOA  //Wake-up pin
#define A_PinN 0      //PA0

//Pin B
#define B_Port GPIOA  //next pin
#define B_PinN 1      //PA1

#define Delay_MS HAL_Delay    //osDelay for FreeRTOS
#define InvCount_max   255
#define InvCount_cut   InvCount_max-4
#define FloatCount_max 20000

typedef struct{
	unsigned char down;
	unsigned char floa;
	unsigned char up;
}Input3;

//b2 error, b1 high stable, b0 low stable
typedef enum{
	Lv_Float = 0b000,
	Lv_Low   = 0b001,
	Lv_High  = 0b010,
	Lv_Midd  = 0b011,
	Lv_Error = 0b100,
}FloatTestLevel;
#define Level_Error_Msk 0b100
#define Level_State_Msk 0b011

// dou't change values
// its can use bit or operation '|'
typedef enum{
	Key_Unk   = 0b00,
	Key_Down  = 0b01,
	Key_Up    = 0b10,
	Key_Error = 0b11,
}KeyState;

typedef struct{
	KeyState K1:2;
	KeyState K2:2;
	KeyState K3:2;
	KeyState K4:2;
	KeyState K5:2;
	KeyState K6:2;
}Key6Struct;

void GPIO2_Key6_Init();
void DetKey6(Key6Struct *k6s);

#endif /* INC_GPIO2_KEY6_H_ */
